home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 027a / proplus.zip / SAMPLE.PRG < prev    next >
Text File  |  1991-03-14  |  15KB  |  363 lines

  1. * WELCOME to the Protection Plus sample program.  This program is heavily
  2. * documented so you can get the feel of how this system works.  A copy of 
  3. * same source is provided in sample1.prg minus the comments.  This is to
  4. * you see just how much code is added to your existing application.  
  5. * Keep in mind that this demo utilizes quite a few of the functions, so
  6. * your application might not need all of it.  This sample, does not make
  7. * reference to any copy protection.  It is only limited as a demo as
  8. * generated by the PROPLUS host program.  
  9.  
  10. * You don't like the way that this demo works, you say?  Well, you are
  11. * more than welcome to change it around to flow exactly how you would like
  12. * it!  Read through all of the comments and play around with the macro
  13. * entry.  This is where you can type in function names and parameters and
  14. * view the results.  Remember that if a mistake is made in typing, a runtime
  15. * error will result.  I recommend that you print out the ASCII manual and
  16. * try out the functions right from there.  Enjoy!
  17.  
  18.  
  19. * The following variable MUST be defined PUBLIC in your program and the
  20. * contents of it should contain the name of the control file minus the 
  21. * extention.
  22.  
  23. PUBLIC pp_cfile, demo_ver
  24. PRIVATE password, get_code, choice, exe_limit
  25. pp_cfile="SAMPLE"
  26.  
  27. * Strings are stored in the control file that tell various information
  28. * about the user and application.  A list of variables can be found in the
  29. * documention.  The following function call, pp_getvar, initializes these
  30. * variables PUBLIC for your use.  If you do not use them, do not call this
  31. * function.
  32.  
  33. if !pp_getvar()
  34.     ? "Error reading control file... Call technical support!"
  35.     ?
  36.     cancel
  37. endif
  38.  
  39. * We can't let the program run if it has come time to expire now, can we?
  40. * The following code determines if the product has expired by date or 
  41. * execution counts?  The date needs to be checked to make sure that no 
  42. * tampering has been done, but this is done after the password screen
  43. * so that a code entry function can be used to bypass the test.  This is
  44. * necessary if the date was accicentally screwed-up and the program stored
  45. * the last date and time used as the screwed-up date
  46. *   2) has the date been tampered with? (date<last used date?)
  47. * NOTE that if it has expired (by date) it is important to perform a 
  48. * pp_upddate() (described later) so that the combination of the date
  49. * checking and the expiration date checking prohibit unauthorized use
  50. * of your application
  51.  
  52. if pp_expired()
  53.     ? "Sorry, but the demo for this product has expired... Please call and"
  54.     ? "order from C.R.S. at 614-676-2771"
  55.     ?
  56.     pp_upddate()
  57.     cancel
  58. endif
  59.  
  60. * The followng checks the date and the time to make sure that the last
  61. * date and time used is less than the current date and time.  If not, the
  62. * user is trying to "back up" the computer clock in order to gain more time
  63. * from your running demo or payment package.  This check is only valid IF
  64. * the current expire type is NOT "None" (which means unlocked).  The test is
  65. * run once.  If it fails, the user can enter the new date and time.  If it
  66. * still fails then he is given an option to enter a code number.  This is
  67. * just in case the user accidentally forwards his DOS date to an advanced
  68. * value and runs the program and then sets it back correctly.  If you do
  69. * not follow this two step check as shown below, the user will NEVER be able
  70. * to set his clock back to the right date.  Upon entering the correct code 
  71. * number, the current DOS date and time is saved into the last used date and
  72. * time field in the control file.  Since the RUN command is highly frowned
  73. * upon, it is recommended to use another method of achieving this result, 
  74. * such as a DOS gateway function like OVERLAY() by Gambit Software or your
  75. * own C function.
  76.  
  77. if !pp_valdate() .AND. pp_exptype()#"N"
  78.     clear
  79.     curr_date=date()
  80.     curr_time=time()
  81.     @ 2,0 say "Please set the date and time correctly:"
  82.     ?
  83.     ?
  84.     run date
  85.     @ 7,0 say "" 
  86.     run time
  87. endif
  88.  
  89. * The description for pp_cenum(), propl0=4500, and pp_ucode() is found
  90. * below.  Please refer there for function explanation.
  91.  
  92. if !pp_valdate() .AND. pp_exptype()#"N"
  93.     clear
  94.     @ 2,0 say "The date and time is still incorrect.  Please call technical support"
  95.     @ 3,0 say "for assistance.              Code entry #: "+ltrim(str(pp_cenum()))+"  Date: "+dtoc(date())
  96.     propl0=4500
  97.     get_code=0
  98.     @ 5,0 say "Enter code: " get get_code picture "@Z"
  99.     read
  100.     if pp_ucode(get_code)=5
  101.         pp_upddate()
  102.         pp_getvar()     && get new values since they just changed
  103.     else
  104.         clear
  105.         cancel
  106.     endif
  107. endif
  108.  
  109. * Set up some global flags
  110. * Is this an execution limit version?  See below for details.
  111. exe_limit=( pp_exptype() = "E" )
  112.  
  113.  
  114. * Here is some basic screen setup
  115. if iscolor()
  116.     setcolor("w+/b")
  117. else
  118.     setcolor("w")
  119. endif
  120. clear
  121. set scoreboard off
  122. @ 0,0 to 24,79
  123. @ 1,13 say "P R O T E C T I O N   P L U S   F O R   C L I P P E R"
  124.  
  125. * The pp_serial function contains the serial number either hard coded in
  126. * the EXE file (by the user-control program) or in the control file.
  127. * The pp_compno function is used optionally to give you a computer "number."
  128. * When the user first calls you to be unlocked (if copy protection is used),
  129. * you enter the number that appears on his screen into the customer record.
  130. * If the user calls and says that his control file was corrupted and you
  131. * need to send another one, when he calls back to unlock the new control
  132. * file and this number is DIFFERENT, he is trying to fool you and install
  133. * your software on another computer.  This adds another level of security
  134. * when the user "acts" stupid!
  135.  
  136. @ 4,2 say "    Serial: "+pp_serial()+"/"+ltrim(str(pp_compno()))
  137.  
  138. * The pp_cenum function returns a code entry number.  This number is 
  139. * random, and leads to the ability to secure hidden procedures in your
  140. * source code and only allow user access when he is online with you.
  141. * Protection Plus gives you ten hidden procedures.  For example, say
  142. * you have a password function in your application and your user forgets
  143. * his password.  He can call you, tell you the code entry number on the
  144. * screen, and you can run the decoder routine (in the host program) with 
  145. * his code entry number as a parameter, and instantly tell him a number to 
  146. * type in response to a special prompt, and the password check is 
  147. * overwritten.  He can then run the program, go to the password change 
  148. * function, and create a new password for future use.  Keep in mind, that
  149. * the code entry number is random, but the actual code to enter in the
  150. * special prompt changes EVERY DAY according to that number.  It would
  151. * be nearly impossible to break the code, eliminating the possiblity of
  152. * one user calling another user and using unauthorized codes.  There are
  153. * so many possiblities available for this section - see the manual text
  154. * file or brochure for more information 
  155.  
  156. @ 5,2 say "Code entry: "+ltrim(str(pp_cenum()))
  157.  
  158. * The following line is to "fix" the code entry number to 4500 ONLY FOR
  159. * THE PURPOSE OF THIS DEMO PROGRAM.  This is so that you can test out the 
  160. * code entry section of this demo.  Your application will let pp_cenum set
  161. * the code entry number.  Run the unlock decoder routine with 4500 as a 
  162. * parameter to find out the codes for today.
  163.  
  164. propl0=4500
  165.  
  166. @  4,64 say "Date: "+dtoc(date())
  167. @  5,59 say "Last used: "+dtoc(propl17)                      && last date used
  168. @  6,70 say propl18                                          && last time used   
  169. @  7,61 say if(!empty(propl10),"Expires: "+dtoc(propl10),"") && expiration date
  170. @  8,24 say "Protection plus sample program!"
  171. @ 10,22 say "This is your power-up screen routine"
  172.  
  173. * The following set key sequence allows for the code entry to be a 
  174. * hot key away from a password retrieval function or inkey(0) sequence.
  175.  
  176. set key -4 to ucode
  177. password=space(8)
  178. do while empty(password) .AND. !lastkey()=27
  179.     @ 20,28 clear to 20,60
  180.     @ 20,30 say "Password: " get password picture "@!"
  181.     read
  182. enddo
  183. set key -4 to 
  184.  
  185. * write your own code here to test password and continue program if ok
  186. if password#"PROPLUS "
  187.     pp_upddate()
  188.     set color to
  189.     clear
  190.     @ 2,0 say "Incorrect password entered, program aborted!"
  191.     @ 4,0 say ""
  192.     cancel
  193. endif 
  194.  
  195. * At this point, the program is allowed to continue.  This is where you
  196. * would stick the first "DO" command to execute your main menu or whatever
  197. * you do next.  For this demo, we have created a menu that allows for
  198. * different functions.  The functions on this menu allow you to further
  199. * check out the Protection Plus library.
  200.  
  201. * The first thing to do is every time the main menu is accessed, the
  202. * execution counter should be incremented if the expire type is set to
  203. * execution limit.  The value of EXE_LIMIT was found in the beginning of 
  204. * the program.
  205. if exe_limit
  206.     pp_advect()
  207. endif
  208.  
  209. clear
  210. @ 0,0 to 24,79
  211. @ 1,13 say "P R O T E C T I O N   P L U S   F O R   C L I P P E R"
  212. choice=1
  213. @ 7,3 to 12,20 
  214. do while .T.
  215.     @ 2,21 clear to 23,78
  216.     @  7,7 say "MAIN MENU"
  217.     @  8,5 prompt "View variables"
  218.     @  9,5 prompt "Edit variables"
  219.     @ 10,5 prompt "Macro entry   "
  220.     @ 11,5 prompt "Exit program  "
  221.     @ 6,29 say "This is the Protection Plus sample program MAIN"
  222.     @ 7,29 say "MENU.  There are some choices here that allow"
  223.     @ 8,29 say "you to test out some of the features of the "
  224.     @ 9,29 say "Protection Plus library.  Look the the source"
  225.     @ 10,29 say "file SAMPLE.PRG for a full description of all"
  226.     @ 11,29 say "the library functions used in this sample"
  227.     @ 12,29 say "program.  It is EASY to implement the source"
  228.     @ 13,29 say "changes in your own existing applications!"
  229.     menu to choice
  230.     do case
  231.         case choice=1
  232.             @ 2,21 clear to 23,78
  233.             * This assumes that pp_getvar() has already been run.  In this
  234.             * sample program, it was run in the very beginning.  This is a
  235.             * very lacking way to allow the user to change internal values.
  236.             * This could very easily be beefed-up a bit.
  237.             @  5,34 SAY "Company: "+propl1
  238.             @  6,34 SAY "   Name: "+propl2
  239.             @  7,34 SAY "Address: "+propl3
  240.             @  8,34 SAY "   City: "+propl4+", "+propl5+"  "+propl6
  241.             @  9,34 SAY "  Phone: "+propl7
  242.             @ 10,34 SAY "Product: "+propl8
  243.             @ 11,34 SAY "Serial#: "+propl9
  244.             @ 12,34 SAY "Expires: "+dtoc(propl10)
  245.             @ 13,34 SAY "Company: "+propl12
  246.             @ 14,34 SAY "Address: "+propl13
  247.             @ 15,34 SAY "         "+propl14
  248.             @ 16,34 SAY "  Phone: "+propl15
  249.             @ 17,34 SAY "    FAX: "+propl16
  250.             @ 18,34 SAY "Last     "+dtoc(propl17)
  251.             @ 19,34 SAY "   Used: "+propl18
  252.             @ 21,34 say "Press any key..."
  253.             inkey(0)
  254.         case choice=2
  255.             @ 2,21 clear to 23,78
  256.             * This assumes that pp_getvar() has already been run.  In this
  257.             * sample program, it was run in the very beginning.
  258.             @  5,34 SAY "Company: " get propl1
  259.             @  6,34 SAY "   Name: " get propl2
  260.             @  7,34 SAY "Address: " get propl3
  261.             @  8,34 SAY "   City: " get propl4
  262.             @  8,61 get propl5
  263.             @  8,65 get propl6
  264.             @  9,34 SAY "  Phone: " get propl7
  265.             @ 10,34 SAY "Product: " get propl8
  266.             @ 11,34 SAY "Serial#: " get propl9
  267.             @ 12,34 SAY "Expires: " get propl10
  268.             @ 13,34 SAY "Company: " get propl12
  269.             @ 14,34 SAY "Address: " get propl13
  270.             @ 15,34 SAY "         " get propl14
  271.             @ 16,34 SAY "  Phone: " get propl15
  272.             @ 17,34 SAY "    FAX: " get propl16
  273.             @ 18,34 SAY "Last     " get propl17
  274.             @ 19,34 SAY "   Used: " get propl18
  275.             read
  276.             if lastkey()#27
  277.                 pp_savepp()
  278.             endif
  279.         case choice=3
  280.             do while lastkey()#27
  281.                 @ 2,21 clear to 23,78
  282.                 string=space(50)
  283.                 @ 10,30 say "Enter macro string:" get string picture "@S20"
  284.                 @ 11,30 say "<ESC> to abort"
  285.                 read
  286.                 if lastkey()#27
  287.                     @ 15,30 say "Result:"
  288.                     @ 15,38 say &string
  289.                     @ 17,30 say "Press any key.."
  290.                     inkey(0)
  291.                 endif
  292.             enddo
  293.         otherwise
  294.             exit_program()
  295.     endcase
  296. enddo .T.
  297. return
  298.  
  299. * A function to clean up screen and update the last used date and time is
  300. * recommended.  The last used date and time should be updated upon exiting
  301. * because if the user keeps setting back the clock, it would be impossible to
  302. * avoid the narrowing window. If he uses the program for an hour every day,
  303. * eventually, no matter how much he changes the date and time, will not
  304. * be able to access the program.  This occurs provided that you run the 
  305. * check date function pp_valdate upon entry.
  306. FUNCTION exit_program
  307.     pp_upddate()
  308.     set color to
  309.     clear
  310.     cancel
  311. return .T.
  312.  
  313.  
  314. * This function you create to get the secret number after the user
  315. * signals the code entry key sequence, whatever you define.  For the purposes
  316. * of this demo, only the result routine number is printed on the screen.
  317. * In your application, you could set up a set of case statements for 
  318. * each value (1-10) to carry out your routines.  A zero is returned if
  319. * an invalid value was entered
  320. * The program can execute a function and continue with the program or
  321. * execute a function and cancel to dos.  You have complete control!  All of
  322. * these functions drop to dos after executing.
  323. FUNCTION ucode
  324.     PRIVATE _routine
  325.     clear gets
  326.     get_code=0
  327.     @ 20,28 say "Enter code: " get get_code picture "@Z"
  328.     read
  329.     if lastkey()=27
  330.         retu .T.
  331.     endif
  332.     _routine=pp_ucode(get_code)
  333.     set color to 
  334.     clear
  335.     do case
  336.         case _routine=1                         && unlock application
  337.             if pp_unlock()
  338.                 @ 2,0 say "Application unlocked..."
  339.             endif
  340.         case _routine=2                         && advance payment date
  341.             if pp_nexptype("P",pp_npdate(date(),20))
  342.                 @ 2,0 say "Application payment expire date extended to "+dtoc(pp_npdate(date(),20))
  343.             endif
  344.         case _routine=3                         && kill protection from disk
  345.             if pp_killprot()
  346.                 @ 2,0 say "Protection erased!"
  347.             endif
  348.         case _routine=4
  349.             if pp_nexptype("D",ctod("4/10/91"))
  350.                 @ 2,0 say "Application demo expire date set to 4/1/91"
  351.             endif
  352.         case _routine=10                        && write copy protection file
  353.             pp_copywrite()
  354.         case _routine=0                         && error
  355.             retu .F.
  356.         otherwise                               && anything else
  357.             @ 2,0 say "Routine # to be executed ="+str(_routine)
  358.     endcase
  359.     @ 4,0 say ""
  360.     exit_program()
  361. return .T.
  362.  
  363.